package com.guigu.www.tangyingmeng.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.guigu.www.mapper.SingleDayAppointmentMapper;
import com.guigu.www.pojo.SingleDayAppointment;
import com.guigu.www.tangyingmeng.service.TymSingleDayAppointmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TymSingleDayAppointmentServiceImpl implements TymSingleDayAppointmentService {

    @Autowired
    private SingleDayAppointmentMapper singleMapper;

    //查询所有预约单
    @Override
    public List<SingleDayAppointment> selSingle() {
        List<SingleDayAppointment> appointments = singleMapper.selectList(null);
        return appointments;
    }

    //查询单个预约单
    @Override
    public SingleDayAppointment selSingleone(String time) {
        QueryWrapper<SingleDayAppointment> wrapper = new QueryWrapper<>();
        wrapper.eq("sin_day_app_date",time);
        SingleDayAppointment appointment = singleMapper.selectOne(wrapper);
        return appointment;
    }

    //添加或修改预约单
    @Override
    public Boolean singleapp(SingleDayAppointment single) {
        if(single.getSinDayAppId() == null){
            int insert = singleMapper.insert(single);
            if(insert>0){
                return true;
            }else {
                return false;
            }
        }else {
            int update = singleMapper.updateById(single);
            if(update>0){
                return true;
            }else {
                return false;
            }
        }
    }
}
